package com.at.bigdata.spark.sql

import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

/**
 *
 * @author cdhuangchao3
 * @date 2023/5/27 8:05 PM
 */
object Spark02_SparkSql_UDF {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("operator")
    val spark = SparkSession.builder().config(sparkConf).getOrCreate()

    import spark.implicits._
    val df = spark.read.json("datas/user.json")
    df.createOrReplaceTempView("user")
    //    spark.sql("select age, 'Name:'+name from user").show()
    spark.udf.register("prefixName", (name: String) => {
      "Name:" + name
    })
    spark.sql("select age, prefixName(name) from user").show()

    spark.close();
  }
}
